{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "\"\"\"\n",
    "   2.疫情数据解析  疫情.json文件  将数据展示为地图格式   每个地区的确诊总人数\n",
    "\"\"\""
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "# 加载json格式数据\n",
    "import json\n",
    "from pyecharts.charts import Map\n",
    "from pyecharts import options as opts\n",
    "with open('yiqing.json', 'r',encoding='utf-8') as f:\n",
    "    data:dict = json.load(f)\n",
    "\n",
    "# 从data中获取每个区域确诊的总人数  dict\n",
    "area_tree_data:list = data.get('areaTree')[0]['children']\n",
    "province_tuple_list = []\n",
    "for area_tree in area_tree_data:\n",
    "    # 地图数据格式[(),()]\n",
    "    province_name = area_tree['name']\n",
    "    if province_name in ['北京','天津','重庆','上海']:\n",
    "        province_name+='市'\n",
    "    elif province_name in ['香港','澳门']:\n",
    "        province_name+='特别行政区'\n",
    "    elif province_name =='新疆':\n",
    "        province_name+='维吾尔自治区'\n",
    "    elif province_name =='广西':\n",
    "        province_name+='壮族自治区'\n",
    "    elif province_name =='宁夏':\n",
    "        province_name+='回族自治区'\n",
    "    elif province_name in ['西藏','内蒙古']:\n",
    "        province_name+='自治区'\n",
    "    else:\n",
    "        province_name+='省'\n",
    "    province_tuple = (province_name,area_tree['total']['confirm'])\n",
    "    province_tuple_list.append(province_tuple)\n",
    "\n",
    "province_map = Map(init_opts={\n",
    "    \"width\": '1200px',\n",
    "    'height': '600px',\n",
    "})\n",
    "province_map.add('',province_tuple_list,maptype='china')\n",
    "# 设置视觉映射区域\n",
    "province_map.set_global_opts(\n",
    "    visualmap_opts=opts.VisualMapOpts(\n",
    "        is_show=True,\n",
    "        is_piecewise= True,\n",
    "        split_number= 5,\n",
    "        max_=2000,\n",
    "        min_=0\n",
    "    ),\n",
    ")\n",
    "province_map.render_notebook()\n",
    "\n"
   ],
   "id": "1e7ca9a2371bc9ae",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "",
   "id": "7d2427ad67383c22",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
